//Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections.Generic;
using System.Text;

namespace Eas.WebCrawler.Test.Scenario {
    public class LogWebFailureAction : NMock2.IAction {
        bool _Fail;
        public LogWebFailureAction() { _Fail = false; }
        public LogWebFailureAction(bool fail) {
            _Fail = fail;
        }

        public static List<string> failures = new List<string>();
        #region IInvokable Members

        public void Invoke(NMock2.Monitoring.Invocation invocation) {
            if (_Fail) {
                _Fail = false;
                throw new System.Exception("Test Injected Error");
            }
            Eas.WebCrawler.Interfaces.UrlFailedEventArgs arg;
            arg = ((Eas.WebCrawler.Interfaces.UrlFailedEventArgs)invocation.Parameters[1]);
            System.Diagnostics.Trace.WriteLine(arg.ResultDescription);
            failures.Add(arg.ResultDescription);
        }

        #endregion

        #region ISelfDescribing Members

        public void DescribeTo(System.IO.TextWriter writer) {
            writer.WriteLine("Trace Handler");
        }

        #endregion
    }
}
